package edu.biwu.service.impl;

import edu.biwu.dao.ProductDao;
import edu.biwu.po.Product;
import edu.biwu.service.ProductService;
import edu.biwu.utils.TransactionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 王俊彪
 * @version 1.0
 */
@Service("productServiceImpl")
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductDao productDao;

    @Override
    public void saveProduct(Product product) {
       /* try {
            transactionManager.beginTransaction();
            productDao.saveProduct(product);
            transactionManager.commit();
        } catch (Exception e) {
            transactionManager.rollBack();
            throw new RuntimeException(e);
        }finally {
            transactionManager.release();
        }*/
        productDao.saveProduct(product);
    }

    @Override
    public void updateProduct(Product product) {
       /* try {
            transactionManager.beginTransaction();
            productDao.updateProduct(product);
            transactionManager.commit();
        } catch (Exception e) {
            transactionManager.rollBack();
            throw new RuntimeException(e);
        } finally {
            transactionManager.release();
        }*/
        productDao.updateProduct(product);
    }

    @Override
    public void deleteProductById(int id) {
       /* try {
            transactionManager.beginTransaction();
            productDao.deleteProductById(id);
            transactionManager.commit();
        } catch (Exception e) {
            transactionManager.rollBack();
            throw new RuntimeException(e);
        } finally {
            transactionManager.release();
        }*/
        productDao.deleteProductById(id);
    }

    @Override
    public List<Product> findAll() {
        return productDao.findAll();
    }

}
